<?php
set_time_limit(0);
$root=preg_replace('/cron$/', '', dirname(__FILE__));

require_once($root."inc.config.php");

require_once($root."initialize.php");

if(($db_msg=cron_initialize()) !== true){

	print_r("Connection error");

}else{ 

	$db=$vars["db"];

	
		$t = @mysql_num_rows($r=mysql_query("SELECT gg_users.* FROM casino1 inner join gg_users on gg_users.id=casino1.id and date_format(gg_users.cdate, '%Y%m%d')<='20140612'"));
		
		if($t<=0)
		{
			print_r("no record");
			exit;
		}
		
		$cdate = date('Y-m-d H:i:s'); $cdate='2014-06-18 04:00:00';
		while($user = mysql_fetch_assoc($r))
		{
			$ewallet_balance = $user['ewallet'];
			if($ewallet_balance>=200){
				$ewallet_balance -= 200;
				mysql_query("update casino1 set ewallet=200 where id=".$user['id']);
				mysql_query("update gg_users set ewallet=".$ewallet_balance." where id=".$user['id']);			
				$sql = "INSERT INTO gg_member_ewallet_record SET uid=".$user['id'].",type='debit',amount=200,bal=".$ewallet_balance.",descr='Transfer to www.paradise-vegas.net',cdate='".$cdate."'";
				mysql_query($sql);			
			}else{
				$amount=mysql_result(mysql_query("select sum(total_bv) from gg_purchase where uid=".$user['id']), 0) or 0;
				if($amount>0){
					$ewallet_balance -= 200;
					mysql_query("update casino1 set ewallet=200 where id=".$user['id']);
					mysql_query("update gg_users set ewallet=".$ewallet_balance." where id=".$user['id']);
					$sql = "INSERT INTO gg_member_ewallet_record SET uid=".$user['id'].",type='debit',amount=200,bal=".$ewallet_balance.",descr='Transfer to www.paradise-vegas.net',cdate='".$cdate."'";
					mysql_query($sql);	
				}
			}			
		}

	print_r("finish");
}
?>